//
//  FeedBackViewController.m
//  SenMo
//
//  Created by ZengYuan on 16/1/20.
//  Copyright © 2016年 ZengYuan. All rights reserved.
//

#import "FeedBackViewController.h"

@interface FeedBackViewController ()

@end

@implementation FeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLabel.text=@"寻求帮助";
    [self.rightBtnPar setTitle:@"发送" forState:UIControlStateNormal];
}

-(void)navRightAction{
 
    if([self.phoneField.text length]==0){
        MBALERT(@"手机号不能为空");
        return;
    }
    
    if([self.addField.text length]==0){
        MBALERT(@"地址不能为空");
        return;
    }
    
    if([self.contentField.text length]==0){
        MBALERT(@"内容不能为空");
        return;
    }
    
    
    
    NSString *sid = [[NSUserDefaults standardUserDefaults] objectForKey:@"session_id"];
    if(!sid)return;
    
    NSDictionary *dic = [[NSDictionary alloc] initWithObjects:
                         @[self.phoneField.text,sid,self.addField.text,self.contentField.text]
                        forKeys:@[@"phoneno",@"session_id",@"address",@"content"]];
    
    NSString *json  =[dic JSONString];
    NSString *url = [NSString stringWithFormat:MAINURL,@"problem_feedback.action"];
    
    [AWHttpTool post:url body:json success:^(id json) {
        
        NSString *msg = HTTPERROR_DATAFAIL;
        
        if (json) {
            
            NSInteger sta = [json[@"status"] integerValue];
            msg = json[@"msg"];
            
            if (sta == 0) {
                MBALERT(@"提交成功");
                [self.navigationController popViewControllerAnimated:YES];
                return ;
            }
        }
        
     } failure:^(NSError *error) {
         MBALERT(@"提交失败");
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
